#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Bootstrap Viewlet Module

Mikan Python Web Framework
"""

__author__ = "K.Sonohara"
__status__ = "develop"
__version__ = "0.0.0_45"
__date__    = "2014/05/04"
__license__ = 'LGPL'

# ------------------------------------------------------------
## Import Section
# ------------------------------------------------------------
# Python

# ESiPC
from esipc import ESiPCProperty

# Mikan
from mikan.view import MikanTemplateXHTMLView
from mikan.viewlet import MikanDivViewlet, MikanImgViewlet, MikanTextViewlet, MikanBodyViewlet,\
	MikanCommentViewlet, MikanJSViewlet, MikanNavViewlet, MikanButtonViewlet, MikanSpanViewlet,\
	MikanAViewlet, MikanH1Viewlet
from mikan.viewlet.bootstrap import MikanBootstrapIconViewlet, MikanBootstrapProgressViewlet
from mikan.viewlet.bootstrap.ui import MikanFootAreaViewlet, MikanMenusViewlet, MikanHeaderAreaViewlet,MikanBootstrapToggleNavigationViewlet,\
	MikanSideBarViewlet

# ------------------------------------------------------------
## Variable Section
# ------------------------------------------------------------

# ------------------------------------------------------------
## Mikan Contant
# ------------------------------------------------------------

# ------------------------------------------------------------
## Function Section
# ------------------------------------------------------------

# ------------------------------------------------------------
## Class Section
# ------------------------------------------------------------

# ------------------------------------------------------------
## MIKAN bootstrap テンプレート XHTMLビュークラス
#
class MikanTitleTemplateBootstrapView(MikanTemplateXHTMLView):

	def add_loading(self, parent, id):
		p = MikanDivViewlet(parent)
		p.id = id
		MikanBootstrapProgressViewlet(p)
		MikanTextViewlet(p, u"読み込み中・・・")

	def set_page_title(self, title):
		if title:
			self.title.nodevalue = title + u" - " + self.request.sitetitle
		else:
			self.title.nodevalue = self.request.sitetitle
		self.FPageTitle = title

	def get_page_title(self):
		return self.FPageTitle

	def get_body(self):
		return self.FBody

	def is_first_theme(self):
		return True

	def get_theme_path(self):
		return ""

	def __init__(self, r, style=None):
		super(MikanTitleTemplateBootstrapView, self).__init__(r)

		self.FPageTitle = ""

		self.FBody = MikanBodyViewlet(self.html)
		self.body.onload = "mikan.page.load();"
		self.body.onunload ="mikan.page.unload();"

		ie = MikanCommentViewlet(self.head, u"[if lt IE 9]")
		ie.nodevalue = u"[if lt IE 9]>\n<script src=\"%s/html5shiv.js\" type=\"text/javascript\">;</script>\n<script src=\"%s/respond.js\" type=\"text/javascript\">;</script>\n<![endif]" % (
			self.request.jsurl,
			self.request.jsurl,
		)
		js = MikanJSViewlet(self.head, value=u"""
var MIKAN_JS_ROOT = '%s';
var MIKAN_WSGI_ROOT = '%s';
var MIKAN_IMAGE_ROOT = '%s';
var MIKAN_HTDOCS_ROOT ='%s';""" % (
self.request.jsurl,
self.request.wsgiurl,
self.request.imageurl,
self.request.htdocsurl,
))

	def perform(self):
		return super(MikanTitleTemplateBootstrapView, self).perform()

	# ----------------------------------------------------
	## Property
	body = ESiPCProperty(get_body, None, None)
	pagetitle = ESiPCProperty(get_page_title, set_page_title, None)

# ------------------------------------------------------------
## MIKAN jQuery Mobile テンプレート XHTMLビュークラス
#
class MikanContentTemplateBootstrapView(MikanTitleTemplateBootstrapView):

	def set_page_title(self, title):
		super(MikanContentTemplateBootstrapView, self).set_page_title(title)

	def get_content_target(self):
		return self.contentcenter

	def get_contents(self):
		return self.FContents

	def get_content_top(self):
		return self.FContentTop

	def get_content_bottom(self):
		return self.FContentBottom

	def get_content_left(self):
		return self.FContentLeft

	def get_content_center(self):
		return self.FContentCenter

	def get_content_right(self):
		return self.FContentRight

	def get_header(self):
		return self.FHeader

	def get_menubar(self):
		return self.FMenuBar

	def get_menubar_menu(self):
		return self.FMenuBarMenu

	def get_menus(self):
		return self.FMenus

	def get_footer(self):
		return self.FFooter

	def __init__(self, r, style=None, container=True):
		super(MikanContentTemplateBootstrapView, self).__init__(r)

		self.FHeader = MikanHeaderAreaViewlet(self.body, [])

		self.FMenus = MikanMenusViewlet(self.body, [])

		if container:
			div = MikanDivViewlet(self.body)
			div.clazz = "container"
		else:
			div = self.body

		self.FContents = MikanDivViewlet(div)
		self.FContents.clazz = "row"

		self.FContentTop = MikanDivViewlet(self.contents)
		self.FContentTop.clazz = "col-md-12"
		self.FContentLeft = MikanDivViewlet(self.contents)
		self.FContentLeft.clazz = "col-md-2"
		self.FContentCenter = MikanDivViewlet(self.contents)
		self.FContentCenter.clazz = "col-md-8"
		self.FContentRight = MikanDivViewlet(self.contents)
		self.FContentRight.clazz = "col-md-2"
		self.FContentBottom = MikanDivViewlet(self.contents)
		self.FContentBottom.clazz = "col-md-12"

		self.FFooter = MikanFootAreaViewlet(self.body)
		self.footer.id = "page_footer"

	def perform(self):
#		MikanHeaderHomeViewlet(self.headerhome)
#		MikanDivViewlet(self.headertitle, self.title.nodevalue).clazz = "title"
#		MikanDivViewlet(self.headertitle, self.request.sitedescription)

		return super(MikanContentTemplateBootstrapView, self).perform()

	# ----------------------------------------------------
	## Property
	contenttarget = ESiPCProperty(get_content_target, None, None)
	contents = ESiPCProperty(get_contents, None, None)
	contenttop = ESiPCProperty(get_content_top, None, None)
	contentbottom = ESiPCProperty(get_content_bottom, None, None)
	contentleft = ESiPCProperty(get_content_left, None, None)
	contentcenter = ESiPCProperty(get_content_center, None, None)
	contentright = ESiPCProperty(get_content_right, None, None)
	header = ESiPCProperty(get_header, None, None)
	menus = ESiPCProperty(get_menus, None, None)
	footer = ESiPCProperty(get_footer, None, None)

class MikanAdminTemplateBootstrapView(MikanTitleTemplateBootstrapView):

	def __init__(self, r, style=None):
		super(MikanAdminTemplateBootstrapView, self).__init__(r)

		self.FContents = MikanDivViewlet(self.body)
		self.FContents.clazz = "wrapper"

		self.FContentNav = MikanNavViewlet(self.contents)
		self.FContentNav.clazz = "navbar navbar-default navbar-static-top"
		self.FContentNav.role = "navigation"
		self.FContentNav.style = "margin-bottom: 0"

		self.FHeader = MikanDivViewlet(self.contentnav)
		self.FHeader.clazz = "navbar-header"

		self.FSideBar = MikanSideBarViewlet(self.contentnav)

		self.FContentPage = MikanDivViewlet(self.contents)
		self.FContentPage.id = "page-wrapper"

		self.FPageHeader = MikanDivViewlet(self.contentpage)
		self.FPageHeader.clazz = "row"

		self.FPageIcon = None

		self.FFooter = MikanDivViewlet(self.body)
		self.footer.id = "page_footer"

	def get_header(self):
		return self.FHeader

	def get_page_header(self):
		return self.FPageHeader

	def set_page_icon(self, value):
		self.FPageIcon = value

	def get_page_icon(self):
		return self.FPageIcon

	def get_contents(self):
		return self.FContents

	def get_content_nav(self):
		return self.FContentNav

	def get_content_page(self):
		return self.FContentPage

	def get_side_bar(self):
		return self.FSideBar

	def get_footer(self):
		return self.FFooter

	def perform(self):
		b = MikanBootstrapToggleNavigationViewlet(self.header)

		a = MikanAViewlet(self.header)
		a.clazz = "navbar-brand"
		a.href = self.request.siteurl
		a.nodevalue = self.request.sitetitle

		if self.pagetitle:
			col12 = MikanDivViewlet(self.pageheader)
			col12.clazz = "col-md-12"
			h1 = MikanH1Viewlet(col12)
			h1.clazz = "page-header"
			if self.pageicon:
				MikanBootstrapIconViewlet(h1, self.pageicon)

			h1.nodevalue = self.pagetitle

		return super(MikanAdminTemplateBootstrapView, self).perform()

	# ----------------------------------------------------
	## Property
	sidebar = ESiPCProperty(get_side_bar, None, None)
	contents = ESiPCProperty(get_contents, None, None)
	contentpage = ESiPCProperty(get_content_page, None, None)
	contentnav = ESiPCProperty(get_content_nav, None, None)
	header = ESiPCProperty(get_header, None, None)
	pageheader = ESiPCProperty(get_page_header, None, None)
	pageicon = ESiPCProperty(get_page_icon, set_page_icon, None)
	footer = ESiPCProperty(get_footer, None, None)


class MikanOleoseTemplateBootstrapView(MikanTitleTemplateBootstrapView):

	def __init__(self, r, style=None):
		super(MikanStandardTemplateBootstrapView, self).__init__(r)

		self.FContents = MikanDivViewlet(self.body)
		self.FContents.clazz = "wrapper"

		self.FContentNav = MikanNavViewlet(self.contents)
		self.FContentNav.clazz = "navbar navbar-default navbar-static-top"
		self.FContentNav.role = "navigation"
		self.FContentNav.style = "margin-bottom: 0"

		self.FHeader = MikanDivViewlet(self.contentnav)
		self.FHeader.clazz = "navbar-header"

		self.FContentPage = MikanDivViewlet(self.contents)
		self.FContentPage.id = "page-wrapper"

		self.FPageHeader = MikanDivViewlet(self.contentpage)
		self.FPageHeader.clazz = "row"

		self.FPageIcon = None

		self.FFooter = MikanDivViewlet(self.body)
		self.footer.id = "page_footer"

	def get_header(self):
		return self.FHeader

	def get_page_header(self):
		return self.FPageHeader

	def set_page_icon(self, value):
		self.FPageIcon = value

	def get_page_icon(self):
		return self.FPageIcon

	def get_contents(self):
		return self.FContents

	def get_content_nav(self):
		return self.FContentNav

	def get_content_page(self):
		return self.FContentPage

	def get_footer(self):
		return self.FFooter

	def perform(self):
		b = MikanBootstrapToggleNavigationViewlet(self.header)

		a = MikanAViewlet(self.header)
		a.clazz = "navbar-brand"
		a.href = self.request.siteurl
		a.nodevalue = self.request.sitetitle

		if self.pagetitle:
			col12 = MikanDivViewlet(self.pageheader)
			col12.clazz = "col-md-12"
			h1 = MikanH1Viewlet(col12)
			h1.clazz = "page-header"
			if self.pageicon:
				MikanBootstrapIconViewlet(h1, self.pageicon)

			h1.nodevalue = self.pagetitle

		return super(MikanStandardTemplateBootstrapView, self).perform()

	# ----------------------------------------------------
	## Property
	contents = ESiPCProperty(get_contents, None, None)
	contentpage = ESiPCProperty(get_content_page, None, None)
	contentnav = ESiPCProperty(get_content_nav, None, None)
	header = ESiPCProperty(get_header, None, None)
	pageheader = ESiPCProperty(get_page_header, None, None)
	pageicon = ESiPCProperty(get_page_icon, set_page_icon, None)
	footer = ESiPCProperty(get_footer, None, None)

# ------------------------------------------------------------
## Main Section
# ------------------------------------------------------------

# ------------------------------------------------------------
